package com.zhss.demo.register.server;

import java.util.LinkedList;
import com.zhss.demo.register.server.ServiceRegistry.RecentlyChangeServiceInstance;

/**
 * 增量数据表的封装类
 */
public class DeltaRegister {
    private LinkedList<RecentlyChangeServiceInstance> recentlyChangeServiceInstances;
    private Long registerInstancesTotal;

    public DeltaRegister() {
    }

    public LinkedList<RecentlyChangeServiceInstance> getRecentlyChangeServiceInstances() {
        return recentlyChangeServiceInstances;
    }

    public void setRecentlyChangeServiceInstances(LinkedList<RecentlyChangeServiceInstance> recentlyChangeServiceInstances) {
        this.recentlyChangeServiceInstances = recentlyChangeServiceInstances;
    }

    public Long getRegisterInstancesTotal(Long registerInstancesTotal) {
        return this.registerInstancesTotal;
    }

    public void setRegisterInstancesTotal(Long registerInstancesTotal) {
        this.registerInstancesTotal = registerInstancesTotal;
    }

    public DeltaRegister(LinkedList<RecentlyChangeServiceInstance> recentlyChangeServiceInstances, Long registerInstancesTotal) {
        this.recentlyChangeServiceInstances = recentlyChangeServiceInstances;
        this.registerInstancesTotal = registerInstancesTotal;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        DeltaRegister deltaRegister = new DeltaRegister();
        LinkedList<RecentlyChangeServiceInstance> tempRecentlyChangeServiceInstances=new LinkedList<RecentlyChangeServiceInstance>();
        for (RecentlyChangeServiceInstance recentlyChangeServiceInstance : recentlyChangeServiceInstances) {
            try {
                tempRecentlyChangeServiceInstances.add((RecentlyChangeServiceInstance) recentlyChangeServiceInstance.clone());
            } catch (CloneNotSupportedException e) {
                e.printStackTrace();
            }
        }
        deltaRegister.setRecentlyChangeServiceInstances(tempRecentlyChangeServiceInstances);
        deltaRegister.setRegisterInstancesTotal(this.registerInstancesTotal);
        return deltaRegister;
    }

    @Override
    public String toString() {
        return "DeltaRegister{" +
                "recentlyChangeServiceInstances=" + recentlyChangeServiceInstances +
                ", registerInstancesTotal=" + registerInstancesTotal +
                '}';
    }
}
